package com.x.reader.dao;

import com.x.framework.Base;
import com.x.framework.dao.BaseDao;
import com.x.reader.model.Category;
import com.x.reader.model.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CategoryDao extends BaseDao {
    private final static String selectCategoryListSql = "select t1.* from reader_category t1 where 1 = 1 ";

    public List<Category> selectCategoryList(Category category) throws Exception {
        StringBuilder sb = new StringBuilder(selectCategoryListSql);
        List params = new ArrayList();
        if (Base.isNotNull(category.getCategoryId())) {
            sb.append("and t1.category_id = ? ");
            params.add(category.getCategoryId());
        }
        if (Base.isNotNull(category.getCategoryParentId())) {
            sb.append("and t1.category_parent_id = ? ");
            params.add(category.getCategoryParentId());
        }
        sb.append("order by category_code");
        return this.queryForList(sb.toString(), Category.class, params);
    }
}
